pacman::p_load(sf, tidyverse, MCI, tmap, ggstatsplot)In-class Ex10
1 Modelling Spatial Interaction: Huff and MCI Models
1.1 Overview
Market area analysis (also known as Trade Area Analysis) is the process of defining and studying the geographical area from which a business draws its customers. It involves analyzing data on consumer demographics, spending habits, and competitors to understand market viability, identify opportunities, and inform decisions about location, marketing, and expansion. It often combines empirical observation, like customer spotting, with mathematical models to identify market segments and understand customer behavior.
Huff model is a geospatial analysis method commonly used in market area analysis to predict the probability that a consumer from a specific area will patronize a particular store, based on the store’s attractiveness and distance relative to competitors. It calculates a store’s market share by considering factors like size or sales for attractiveness and distance or travel time, with the probability decreasing as distance or competition increases. This tool helps businesses assess potential revenue, define trade areas, and make informed decisions about site selection
1.1.1 Learning Outcome
In this hands-on exercise, you will gain hands-on experience on how to perform market area analysis by using Huff model of MCI packages.
By the end of this hands-on exercise, you will be able:
- to import GIS data into R and save them as simple feature data frame by using appropriate functions of sf package of R;
- to import aspatial data into R and save them as simple feature data frame by using appropriate functions of sf package of R;
- to clean and tidy the data sets so that they are ready for the analysis,
- to compute distance matrix between the origins (i.e. villages) and destinations (i.e stores),
- to computer interaction probability using Huff model, and
- to visualise the market area by using tmap and ggplot2 packages.
1.1.2 Setting the scene
A fast-food franchise is a business model in which an individual (the franchisee) acquires the rights to operate a restaurant under an established brand owned by a franchisor. This arrangement typically involves franchise fees and adherence to standardized operational procedures. Key considerations prior to investment include the scale of initial capital outlay, the strength of the brand, and the strategic importance of store location. Capital investment requirements vary significantly, generally ranging from approximately $200,000 to more than $2 million. Major global fast-food franchise brands include McDonald’s, Burger King, Pizza Hut, KFC, and Taco Bell.
In this exercise, you will assume the role of a data analyst within the business development team of a fast-food franchise. Your objective is to delineate the trade areas of existing stores in Taichung City and to produce corresponding spatial maps to support market analysis and strategic decision-making.
1.1.3 The data
Four data sets will be used in this hands-on exercise, they are:
Geospatial data
- STORES_TN, store locations data in ESRI shapefile format.
- VILLAGE_TN, village boundary data in ESRI shapefile format.
Aspatial data
- pop2019.csv, population data of Taichung City in 2019. H_CNT, P_CNT, M_CNT, and F_CNT indicate Number of household, Total population, Male population and Female population respectively.
- Store_sales_data.csv provides store sales data, and
1.2 Getting Started
Before we getting started, it is important for us to install the necessary R packages and launch them into RStudio environment.
The R packages need for this exercise are as follows:
- sf for handling geospatial data and performing geoprocessing function such as computing distance matrix,
- MCI for performing Huff and MCI modelling,
- tidyverse for performing data science tasks including visualisation,
- ggstatsplot, an R package that extends the ggplot2 visualization package to combine data visualization with statistical analysis, creating plots that include statistical test results directly, and
- tmap for plotting cartographic quality thematic maps.
The code chunk below installs and launches these R packages into RStudio environment.
1.3 Importing Data
1.3.1 Importing geospatial data
First, st_read() of sf package will be used to import the three geospatial data sets into R environment by using the code chunk below.
stores <- st_read(
dsn = "/Users/cktan/Desktop/SMU/01_Geospatial Analytics (ISSS626)/Hands-on_Ex/In-Class_Ex10/data/geospatial",
layer = "STORES_TC")Reading layer `STORES_TC' from data source
`/Users/cktan/Desktop/SMU/01_Geospatial Analytics (ISSS626)/Hands-on_Ex/In-Class_Ex10/data/geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 28 features and 3 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 202702.9 ymin: 2662196 xmax: 232773.2 ymax: 2693557
Projected CRS: TWD97 / TM2 zone 121
town <- st_read(
dsn = "/Users/cktan/Desktop/SMU/01_Geospatial Analytics (ISSS626)/Hands-on_Ex/In-Class_Ex10/data/geospatial",
layer = "TOWN_TC")Reading layer `TOWN_TC' from data source
`/Users/cktan/Desktop/SMU/01_Geospatial Analytics (ISSS626)/Hands-on_Ex/In-Class_Ex10/data/geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 28 features and 7 fields
Geometry type: POLYGON
Dimension: XY
Bounding box: xmin: 194797.1 ymin: 2654887 xmax: 240450.2 ymax: 2703838
Projected CRS: TWD97 / TM2 zone 121
village <- st_read(
dsn = "/Users/cktan/Desktop/SMU/01_Geospatial Analytics (ISSS626)/Hands-on_Ex/In-Class_Ex10/data/geospatial",
layer = "VILLAGE_TC")Reading layer `VILLAGE_TC' from data source
`/Users/cktan/Desktop/SMU/01_Geospatial Analytics (ISSS626)/Hands-on_Ex/In-Class_Ex10/data/geospatial'
using driver `ESRI Shapefile'
Simple feature collection with 622 features and 10 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 194797.1 ymin: 2654887 xmax: 240450.2 ymax: 2703838
Projected CRS: TWD97 / TM2 zone 121
The output print above shown that the three data sets are in TWD97 / TM2 zone 121 (i.e epsg: 3826) projected coordinates systems.
For any geospatial analysis, it is important to check and confirm that all the geospatial data are in the similar projected coodinates system.
tmap_mode("view")ℹ tmap mode set to "view".
tm_shape(town) +
tm_polygons() +
tm_shape(village) +
tm_polygons() +
tm_shape(stores) +
tm_dots()Registered S3 method overwritten by 'jsonify':
method from
print.json jsonlite